package com.example.springboot.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.springboot.entity.Book_Categories;
import com.example.springboot.mapper.CateMapper;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Administrator邓
 */
@RestController
public class CateController {

    private final CateMapper cateMapper;

    public CateController(CateMapper cateMapper) {
        this.cateMapper = cateMapper;
    }

    @GetMapping("/getCategories")
    public List<Map<String, Object>> getCategories() {
        // 创建查询条件
        QueryWrapper<Book_Categories> queryWrapper = new QueryWrapper<>();
        // 执行查询操作获取所有分类
        List<Book_Categories> allCategories = cateMapper.selectList(queryWrapper);

        List<Map<String, Object>> result = new ArrayList<>();
        for (Book_Categories category : allCategories) {
            Map<String, Object> categoryMap = new HashMap<>();
            categoryMap.put("categoryName", category.getCategoryName());
            categoryMap.put("subcategoryName", category.getSubcategoryName());
            categoryMap.put("specificItem", category.getSpecificItem());
            result.add(categoryMap);
        }

        return result;
    }
}